#[cfg(test)]
mod tests {
    use std::path::PathBuf;
    use serde_yaml::Value;
    use attestation_common::{yaml_get, YamlValue};

    fn get_test_data_path(file_name: &str) -> PathBuf {
        let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
        manifest_dir
            .join("tests")
            .join("data")
            .join(file_name)
    }

    #[test]
    fn test_yaml_parser() {
        // parse YAML file
        let path = get_test_data_path("test_config.yaml");
        let yaml = YamlValue::from_file(path.to_str().unwrap()).unwrap();

        // 1. Test top-level fields
        if let Some(name) = yaml_get!(yaml.clone(), "name" => str) {
            assert_eq!(name, "Test Project");
            println!("✅ name: {}", name);
        }

        // 2. Test nested fields
        if let Some(message) = yaml_get!(yaml.clone(), "attestation_common.message" => str) {
            assert_eq!(message, "Processing in progress");
            println!("✅ message: {}", message);
        }

        // 3. Test Boolean
        if let Some(is_finish) = yaml_get!(yaml.clone(), "attestation_common.is_finish" => bool) {
            assert!(!is_finish);
            println!("✅ is_finish: {}", is_finish);
        }

        // 4. Test number type
        if let Some(progress) = yaml_get!(yaml.clone(), "attestation_common.info.progress" => u64) {
            assert_eq!(progress, 85);
            println!("✅ progress: {}", progress);
        }

        if let Some(percentage) = yaml_get!(yaml.clone(), "attestation_common.info.percentage" => f64) {
            assert!((percentage - 92.5).abs() < f64::EPSILON);
            println!("✅ percentage: {}", percentage);
        }

        // 5. Test array
        if let Some(tags) = yaml_get!(yaml.clone(), "attestation_common.info.tags" => array) {
            assert_eq!(tags.len(), 3);
            assert_eq!(tags[1].as_str().unwrap(), "rust");
            println!("✅ tags: {:?}", tags);
        }

        // 6. Test mapping
        if let Some(metadata) = yaml_get!(yaml.clone(), "attestation_common.info.metadata" => map) {
            let author = metadata.get(&Value::String("author".to_string()))
                .and_then(|v| v.as_str())
                .unwrap();
            assert_eq!(author, "Alice");
            println!("✅ author: {}", author);
        }

        // 7. Test default value
        let missing_value = yaml_get!(yaml.clone(), "nonexistent.key" => str, or "default").unwrap();
        assert_eq!(missing_value, "default");
        println!("✅ default value: {}", missing_value);

        // 8. Test custom transformations
        let custom_status = yaml_get!(yaml.clone(), "attestation_common.info.status" => custom |v: &YamlValue| {
            v.as_str().map(|s| s.to_uppercase())
        }).unwrap();
        assert_eq!(custom_status, "CODING"); // 假设 YAML 中有 status: "coding"
        println!("✅ custom status: {:?}", custom_status);

        // 9. Test key names with dots
        if let Some(value) = yaml_get!(yaml.clone(), "key.with.dots" => str) {
            assert_eq!(value, "This key contains dots");
            println!("✅ key.with.dots: {}", value);
        }
    }
}